<html>
<head>
<link href="../../../Objects/sofa_white.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<div id="contenu">
		
		<center><h3>Creation of a Scene (7/9)</h3></center>
		<center><img src="6_FullObject.png" width="300" name="FullObject" align="middle"></center>
		
		<br><div id="orangeText">Description</div>

		<p>Like we did in <a href="4_FullObject.scn">this part</a> of the tutorial, we will map another model to the simulated mechanical object.
		This time, it won't be only a visual model, but a mechanical object which aims at handling the collisions, and to transmit the forces due to the collision response to the simulated object. <br>
                Once this model is able to transmit the forces, we just need to add some collision models like we did <a href="5_FullObject.scn">here </a></p>
                <p>Remember:
                <ul>
                  <li> <u>Visual Mapping</u>: the information is passed Top-Down: the simulated object propagates the positions  <i>(method apply) </i> and the velocities <i>(method applyJ)</i> to the mapped model</li>
                  <li> <u>Mechanical Mapping</u>: the information is passed both ways: the simulated object propagates the positions  <i>(method apply) </i> and the velocities  <i>(method applyJ) </i> to the mapped model, and on the other site, the mapped model propagates the forces to the simulated object  <i>(method applyJT) </i></li>
                </ul></p>


		<div id="orangeText">Key points</div>
        
        <p><div id="tutorialAction">Add a new <strong>GNode</strong> to the <strong>Object</strong> node, and rename it "CollisionNode".</div></p>
        
        <p>Now we need to load the model from a mesh file. As a first example we will use a cube as the collision object.</p>
        
        <p><div id="tutorialAction">Add a <strong>MeshTopology</strong> to the <strong>CollisionNode</strong>, and change the <strong>Filename of the mesh</strong> to 
        <strong>/mySofaDirectory/Sofa/share/mesh/cube.obj</strong>.</div></p>
        
        <p>Next we need a MechanicalObject to store the positions, velocities and forces of the collision object</p>
        
        <p><div id="tutorialAction">Add a <strong>MechanicalObject</strong> to the <strong>CollisionNode</strong>. Change the <strong>Scale of the DOFs in 3 dimensions</strong> property to "(6 6 6)".</div></p>
        
        <p>The collision object is mapped to the simulated deformable model using a Mapping, this time a MechanicalMapping: <b>BarycentricMapping</b>. You may wonder what the difference is between this mapping and the one used for the visual model, as we are using the same component! What makes a mapping visual or mechanical?</p>
        
        <p>This is determined by the template used to create the mapping:</p>
        
        <p><div id="tutorialAction">Find the <strong>BarycentricMapping</strong> component using the <strong>Filter</strong>. From the dropdown menu, select <strong>Vec3d, Vec3d</strong>.</div></p>
        
        <p>This mean it transforms a state expressed by Vec3d type into Vec3d. <strong>Remember</strong>, collision models are only expressed in Vec3d type, so the mapped state <strong>must</strong> be of Vec3d types.</p>
        
		<p><div id="tutorialAction">Open the <strong>BarycentricMapping</strong> properties and go to the <strong>Properties 2/2</strong> tab. Set the <strong>Input object to map</strong> to "@.." and the <strong>Output object to map</strong> to "@."</div></p>
        
        <p>This corresponds to mapping from the <strong>MechanicalObject</strong> from one node above to the <strong>MechanicalObject</strong> of the current node.</p>
        
        <p>Finally, we will remove our old <strong>TSphereModel</strong>, and replace it with one in the <strong>CollisionNode</strong></p>
        
        <p><div id="tutorialAction">Delete the current <strong>TSphereModel</strong>. Add a new <strong>TSphereModel</strong> to the <strong>CollisionNode</strong>, and change the <strong>Default contact stiffness</strong> property to "1000".</div></p>

		<br><div id="orangeText">Results</div>
        
        <p><div id="tutorialAction">Run in SOFA. Change to <strong>DT</strong> to "0.005". Animate.</div></p>
        
        <p>You can see height spheres, corresponding to the height corners of the cube chosen to represent our collision mode. Of course, using four height spheres to do the collision detection is much faster than 171 as in the previous scene. But the behavior is also very different.</p>
        
        <p><div id="tutorialAction">Apply a force on one of the spheres by holding down the <strong>Shift</strong> key, and clicking and dragging a sphere with the mouse.</div></p>
        
         <p> You will be able to deform the object. This is due to the <strong>MechanicalMapping</strong>.</p>
         
        <p>We display some debug information about the mechanical mapping using blue lines. Each point of the collision model depends on several points of the simulated object. If a force is applied to one of the collision model's points, the force will be propagated to all the points that depend on it.</p>                 

                <br><center><h3><a href="5_FullObject.scn">Previous</a> ____________  <a href="7_FullObject.scn">Next</a></center></h3>
	</div>
</body>
</html>
